﻿<section class="container-fluid case" style="background-color: white;">
    <div class="data-tool clearfix">
        <form class="form-horizontal m15_t" id="form">
            <div class="tab-content">
                <div class="tab-pane fade in active" id="home">
                    <div class="form-group">
                        <label class="wd120 control-label"><span class="WdateFmtErr">*</span>单据编号：</label>
                        <div class="wd400 m15_l">
                            <input class="form-control input-xs" name="orderId" type="text" value="@(ViewBag.OrderId)" data-options="required:true,prompt:'单据编号'">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd120 control-label m15_l"><span class="WdateFmtErr">*</span>库存：</label>
                        <div class="input-group wd400 m15_l">
                            <input class="form-control" type="text" name="resourceId" maxlength="20" placeholder="请选择出库单" autocomplete="off" disabled />
                            <span class="input-group-addon inventoryOrder" style="margin-left:20px;">
                                <i data-title="库存" data-width="1000" data-height="560" class="glyphicon glyphicon glyphicon-align-justify"></i>
                            </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd120 control-label"><span class="WdateFmtErr">*</span>站台：</label>
                        <div class="wd400 m15_l">
                            <select name="stationNo" class="form-control" >
                                <option value="">请选择站台</option>
                                <option value="1">1->D14a出口</option>
                                <option value="2">2->D14出口</option>
                                <option value="3">3->D2A出口</option>
                                <option value="5">5->D5出口</option>
                                <option value="7">7->D2出口</option>
                                <option value="9">9->D11出口</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd120 control-label">备注：</label>
                        <div class="wd400 m15_l">
                            <input class="form-control" type="text" name="remark" maxlength="40" autocomplete="off" placeholder="长度必须介于 0 和 40 之间">
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</section>

@section footerScript{
    <script type="text/javascript">
        $(function () {
            $(".inventoryOrder").click(function() { 

                var initFun = function() {
                    this.button(
                        {
                            name: "保存",
                            callback: function() {
                                var iframe = this.iframe.contentWindow;
                                if (!iframe.document.body) {
                                    return false;
                                }
                                iframe.save();
                                return false;
                            },
                            focus: true,
                        },
                        {
                            name: '取消'
                        }
                    );
                };
                Topro.UI.DialogOpen('/Module/Inventory', {
                    title: "库存",
                    width: 1000,
                    height: 560,
                    init: initFun,
                });
            });
        });

        function Tip_success(word) {
            Topro.UI.Tip_success(word);
        }

        function set(obj) {
            $("input[name='resourceId']").val(obj.resourceId);
        }

        function view(obj, url) {
            var confirmname = "保存";

            if ($(obj).data("confirmname") != undefined && $(obj).data("confirmname") != "") {
                confirmname = $(obj).data("confirmname");
            }

            var initFun = function() {
                this.button(
                    {
                        name: confirmname,
                        callback: function() {
                            var iframe = this.iframe.contentWindow;
                            if (!iframe.document.body) {
                                return false;
                            }
                            iframe.save();
                            return false;
                        },
                        focus: true,
                    },
                    {
                        name: '取消'
                    }
                );
            };

            if ($(obj).data("bottom") == "remove") {
                initFun = function() { };
            }

            Topro.UI.DialogOpen(url, {
                title: $(obj).data("title"),
                width: $(obj).data("width"),
                height: $(obj).data("height"),
                init: initFun,
            });
        }

        function save() {
            //出库
            var stockOut = {};
            //资源编号
            stockOut.orderId = $("input[name='orderId']").val();
            //资源编号
            stockOut.resourceId = $("input[name='resourceId']").val();
            //订单类型
            stockOut.orderType = $("input[name='orderType']").is(':checked') == true ? 40 : 20;
            //站台
            stockOut.stationNo = $("select[name='stationNo']").find("option:selected").val();
            //备注
            stockOut.remark = $("input[name='remark']").val();

            Topro.UI.DialogBox({
                id: 'dialog_confirm',
                title: '操作',
                parent: true,
                lock: true,
                fixed: true,
                icon: 'question',
                padding: '20px 15px 20px 10px',
                ok: function () {
                    Topro.UI.Ajax({
                        type: "POST",
                        url: "/StockOut/Save",
                        data: {
                            stockOut: stockOut
                        },
                        success: function (res) {
                            if (res.success) {
                                Topro.UI.DialogOpener().Tip_success("操作成功！");
                                Topro.UI.DialogOpener().Out.doSearch();
                                Topro.UI.CloseDialog();
                            } else {
                                Topro.UI.Tip_warning("操作失败！" + res.message);
                            }
                        },
                        error: function (e) {
                            Topro.UI.Tip_warning("操作失败！请查看网络，请重试。");
                        }
                    });
                },
                width: '200px',
                content: '您确认要操作出库?',
                cancel: function () {

                }
            });
        }

        function doSearch() {
            Topro.UI.Pager(".paging", { pageSize:5,ajax: { url: '@Url.Action("InventoryQuery", "Inventory")' } });
        }
    </script>
}
